import pandas as pd
from collections import Counter
import numpy as np

# 假设已有的六合彩数据
data = pd.read_csv('/Users/wulinghui/Downloads/macaujc2.csv')
data = data.iloc[::-1].reset_index(drop=True)  # 倒排数据

# 定义窗口大小  120(0.52) 150(0.51)  190(512)  210(508)
window_size = 120
cur_data = data[len(data) - window_size :len(data)]
# 所有数字范围
all_numbers = range(1, 50)
number_counts = Counter()

# 计算每个数字的出现频率
for index, row in data.iterrows():
    numbers = row[['normalCode1', 'normalCode2', 'normalCode3', 'normalCode4', 'normalCode5', 'normalCode6' , 'code']]
    number_counts.update(numbers)

# 使用拉普拉斯平滑
total_draws = len(data)

alpha = 1  # 拉普拉斯平滑的平滑参数
smoothed_probabilities = {num: (number_counts[num] + alpha) / (total_draws + len(all_numbers) * alpha) for num in all_numbers}

# 根据概率排序，选择概率最大的前 24 个数字
predicted_top_numbers = sorted(smoothed_probabilities, key=smoothed_probabilities.get, reverse=True)[:24]
print("预测的最有可能出现的号码：", predicted_top_numbers)

# 对号码进行从小到大的排序
sorted_top_24_codes = sorted(predicted_top_numbers)

print("预测的最有可能的 24 个 code 值：", sorted_top_24_codes)
